package com.food.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.food.mapper.CaloriesRecordsUserMapper;
import com.food.pojo.*;
import com.food.result.Result;
import com.food.service.CaloriesService;
import com.food.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author beixiang
 * @version 1.0
 * @description TODO
 * @date 2023/6/16 17:20
 */

@Api(tags = "美食卡路里相关接口")
@CrossOrigin("*")
@RestController
@RequestMapping("/api/Calories")
public class CaloriesController {

    @Autowired
    CaloriesService caloriesService;

    /**
     * 添加自定义美食列表接口
     */
    @ApiOperation(value = "添加自定义美食列表接口")
    @PostMapping("/add/customize_foods")
    public Result setCaloriesFoodsUsers(@RequestBody CaloriesFoodUser caloriesFoodUser){
        if(caloriesFoodUser==null){
            return Result.fail("参数为空");
        }
        Boolean aBoolean = caloriesService.insertCaloriesFoodUser(caloriesFoodUser);
        if(aBoolean)
        {
            return Result.ok();
        }else {
            return Result.fail("添加失败");
        }

    }


    /**
     * 删除自定义美食列表接口
     */
    @ApiOperation(value = "删除自定义美食列表接口")
    @DeleteMapping("/delete/customize_foods/{Id}")
    public Result deleteCaloriesFoodsUsers(@PathVariable(value = "Id") Integer Id){
        Boolean aBoolean = caloriesService.deleteCaloriesFoodUser(Id);
        if(aBoolean)
        {
            return Result.ok();
        }else {
            return Result.fail("删除失败");
        }
    }

    /**
     * 用户自定义美食卡路里默认展示列表接口
     */
    @ApiOperation(value = "用户自定义美食卡路里默认展示列表接口")
    @GetMapping("/select/customize_foods")
    public Result getUsersCaloriesFoods( @RequestParam("page") Integer page,
                                         @RequestParam("limit") Integer limit){
        Page<CaloriesFoodUser> caloriesFoodUserPage = caloriesService.selectCaloriesFoodUser(page, limit);
        return Result.ok(caloriesFoodUserPage);
    }

    /**
     * 美食卡路里默认展示列表接口
     */
    @ApiOperation(value = "美食卡路里默认展示列表接口")
    @GetMapping("/select/foods")
    public Result getCaloriesFoods( @RequestParam("page") Integer page,
                                    @RequestParam("limit") Integer limit){
        Page<CaloriesFood> caloriesFoodPage = caloriesService.selectCaloriesFood(page, limit);
        return Result.ok(caloriesFoodPage);
    }

    /**
     * 查询原有美食卡路里列表接口
     */
    @ApiOperation(value = "查询美食卡路里列表接口")
    @GetMapping("/select/search_foods")
    public Result searchCaloriesFoods(     @RequestParam("keyword") String keyword,
                                              @RequestParam("page") Integer page,
                                              @RequestParam("limit") Integer limit){
        return null;
    }


    /**
     * 传入id集合，添加用户美食记录接口
     */
    @ApiOperation(value = "添加用户美食记录接口")
    @PostMapping("/add/calories_Records")
    public Result setCaloriesRecords(@RequestBody List<RecordsDto> recordsDtos){
        Boolean aBoolean = caloriesService.insertCaloriesRecordsUser(recordsDtos);
        if (aBoolean){
            return Result.ok();
        }else{
            return Result.fail();
        }

    }

    /**
     * 查询用户卡路里余量接口
     */
    @ApiOperation("查询用户卡路里余量接口")
    @GetMapping("/user/calories/{userId}")
    public Result getUserRemainingCalories(@PathVariable Integer userId) {
        CaloriesIngestibleUserDto userRemainingCalories = caloriesService.getUserRemainingCalories(userId);
        return Result.ok(userRemainingCalories);
    }

    /**
     * 查询用户每日饮食添加记录接口
     */
    @ApiOperation("查询用户每日饮食添加记录接口")
    @GetMapping("/user/records/calories/{userId}")
    public Result getUserCaloriesToday(@PathVariable Integer userId) {
        CaloriesRecordsUserDto userCaloriesToday = caloriesService.getUserCaloriesToday(userId);
        return Result.ok(userCaloriesToday);
    }

    /**
     * 添加用户运动消耗记录接口
     */
    @ApiOperation("添加用户运动消耗记录接口")
    @PutMapping("/user/calories")
    public Result addUserReduceCalorie(@RequestBody CaloriesRecordsUser caloriesRecordsUser) {
        caloriesService.addUserReduceCalorie(caloriesRecordsUser);
        return Result.ok();
    }
}
